package com.atguigu.tingshu.live.api;

import com.atguigu.tingshu.common.constant.RedisConstant;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.live.service.LiveRoomService;
import com.atguigu.tingshu.model.live.LiveRoom;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.vo.live.LiveRoomVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("api/live/liveRoom")
@SuppressWarnings({"unchecked", "rawtypes"})
public class LiveRoomApiController {

	@Autowired
	private LiveRoomService liveRoomService;

	/**
	 * 获取当前正在直播的直播间
	 * @return
	 */
	@GuiGuLogin
	@Operation(summary = "获取当前正在直播的直播间")
	@GetMapping("getCurrentLive")
	public Result getCurrentLive(){
		//	获取用户Id
		Long userId = AuthContextHolder.getUserId();
		//	调用服务层方法.
		LiveRoom liveRoom = this.liveRoomService.getCurrentLive(userId);
		//	返回数据
		return Result.ok(liveRoom);
	}

	/**
	 * 创建直播间
	 * @return
	 */
	@GuiGuLogin
	@Operation(summary = "创建直播")
	@PostMapping("saveLiveRoom")
	public Result saveLiveRoom(@RequestBody LiveRoomVo liveRoomVo){
		//	获取用户Id
		Long userId = AuthContextHolder.getUserId();
		//	调用服务层方法。
		LiveRoom liveRoom = this.liveRoomService.saveLiveRoom(userId,liveRoomVo);
		//	返回数据,创建完成之后，需要看直播间的信息
		return Result.ok(liveRoom);
	}

	/**
	 * 查看直播间列表
	 * @return
	 */
	@GuiGuLogin
	@Operation(summary = "获取当前直播列表")
	@GetMapping("findLiveList")
	public Result findLiveList(){
		//	调用服务层方法.
		List<LiveRoom> liveRoomList = this.liveRoomService.findLiveList();
		return Result.ok(liveRoomList);
	}

	/**
	 * 获取直播间信息
	 * @return
	 */
	@GuiGuLogin
	@Operation(summary = "根据id获取信息")
	@GetMapping("getById/{id}")
	public Result getById(@PathVariable Long id){
		//	获取数据
		return Result.ok(this.liveRoomService.getById(id));
	}


}

